<template>
  <div class="app-container">
    <el-form
      ref="form"
      :model="form"
      :rules="rules"
      label-width="120px" style="padding-left: 50px;padding-right: 50px;">
      <el-row>
        <el-col :span="20">
          <div>
            <span style="color: #000;font-weight: bold;">Basic information</span>
          </div>
        </el-col>
        <el-col :span="4">
          <el-upload
            multiple
            :action="uploadFileUrl"
            :before-upload="handleBeforeUploadCV"
            :file-list="fileList"
            :limit="limit"
            :on-error="handleUploadErrorCV"
            :on-exceed="handleExceedCV"
            :on-success="handleUploadSuccessCV"
            :show-file-list="false"
            :headers="headers"
            class="upload-file-uploader"
            ref="fileUpload"
          >
            <!-- 上传按钮 -->
            <el-button size="mini" type="primary">cn-import</el-button>
            <!-- 上传提示 -->
            <div class="el-upload__tip" slot="tip" v-if="false">
              请上传
              <template v-if="fileSize"> size <b style="color: #f56c6c">{{ fileSize }}MB</b> </template>
              <template v-if="fileType"> format <b style="color: #f56c6c">{{ fileType.join("/") }}</b> </template>
              的文件
            </div>
          </el-upload>
        </el-col>
      </el-row>
      <el-row style="margin-top: 20px;">
        <el-col :span="8">
          <el-form-item label-width="60px" label="Name" prop="name">
            <el-input v-model="form.name" placeholder="" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label-width="80px" label="Gender" prop="gender">
            <el-select v-model="form.gender" placeholder="">
              <el-option
                v-for="dict in dict.type.sys_user_sex"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label-width="60px" label="Email" prop="email1">
            <el-input v-model="form.email1" placeholder="" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label-width="60px" label="Birth" prop="birthyear">
            <el-date-picker
              v-model="form.birthyear"
              value-format="yyyy"
              type="year"
            ></el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label-width="60px" label="Area" prop="area">
            <el-select
              v-model="form.area"
              @change="selectAreaChange">
              <el-option
                v-for="dict in dict.type.sys_mhk_district"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="isMainlang">
          <el-form-item label-width="60px" label="District" v-if="isCascaderShow">
            <el-cascader
              ref="cascader"
              :options="options"
              :props="{ multiple: false }"
              v-model="optionsCity"
              collapse-tags
              clearable
              @change="searchBuilds"
              placeholder=""
            ></el-cascader>
          </el-form-item>
        </el-col>
        <el-col :span="8" v-if="isHK">
          <el-form-item label-width="80px" label="District" prop="district">
            <el-select
              v-model="form.district"
              clearable
              filterable
              @blur="selectBlur"
              @clear="selectClear"
              @change="selectChange">
              <el-option
                v-for="dict in dict.type.sys_hk_district"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="8">
          <el-form-item label-width="60px" label="Phone" prop="phone1">
            <el-input v-model="form.phone1" placeholder="" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label-width="130px" label="Expected Salary" prop="salary">
            <el-input v-model="form.salary" placeholder="" />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="Job Function" prop="jobFunction">
            <el-input v-model="form.jobFunction" placeholder="" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row style="margin-top: 20px;">
        <el-col :span="12">
          <el-upload
            :action="uploadUrl"
            :on-preview="handlePreview"
            :on-remove="handleRemove"
            :before-remove="beforeRemove"
            accept=".pdf,.doc,.docx"
            name="file"
            :headers="headers"
            multiple
            :limit="100"
            ref="upload"
            :on-exceed="handleExceed"
            :on-success="handleFileSuccess"
            :file-list="form.fileList">
            <div style="display: flex;align-items: center;">
              <i class="el-icon-upload" style="font-size: 35px;"></i>
              <span style="color: #99a9bf;font-size: 15px;margin-left: 2px;">Upload</span>
            </div>
            <!--<el-button size="small" type="primary">点击上传</el-button>-->
            <div slot="tip" class="el-upload__tip">Format pdf/word</div>
          </el-upload>
        </el-col>
      </el-row>

      <div style="margin-top: 50px;">
        <span style="color: #000;font-weight: bold;">Work experience</span>
        <div style="margin-top: 20px;">
          <el-form v-for=" (item,index) in form.ccompanyList"
                   :key="index" :model="item" :ref="'formData'+index"
                   label-width="80px"
                   style="border-bottom: 2px dotted #cccccc;margin-top: 10px">
            <div style="display: inline-flex;flex-direction: row-reverse;width: 100%;">
              <el-button
                @click="removeJobs(index)"
                type="danger"
                icon="el-icon-delete"
                circle size="mini"></el-button>
            </div>
            <el-row>
              <el-col :span="8">
                <el-form-item label="Company" prop="com">
                  <el-input v-model="item.com" placeholder="" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="Title" prop="title">
                  <el-input v-model="item.title" placeholder="" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="Start Date">
                  <el-date-picker
                    v-model="item.startTime"
                    value-format="yyyy-MM"
                    type="month"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="End Date">
                  <el-date-picker
                  v-model="item.endTime"
                  value-format="yyyy-MM"
                  type="month"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label-width="80px" label="Description">
                  <editor v-model="item.description" :min-height="392" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <el-button
          type="primary"
          round
          style="font-size: 12px;padding: 8px 12px;margin-top: 10px;"
          @click="addJobs">+Add New</el-button>
      </div>

      <div style="margin-top: 50px;">
        <span style="color: #000;font-weight: bold;">Project experience</span>
        <div style="margin-top: 20px;">
          <el-form v-for=" (item,index) in form.proList"
                   :key="index" :model="item" :ref="'formData'+index"
                   label-width="80px"
                   style="border-bottom: 2px dotted #cccccc;margin-top: 10px">
            <div style="display: inline-flex;flex-direction: row-reverse;width: 100%;">
              <el-button
                @click="removePro(index)"
                type="danger"
                icon="el-icon-delete"
                circle size="mini"></el-button>
            </div>
            <el-row>
              <el-col :span="8">
                <el-form-item label="Title" prop="title">
                  <el-input v-model="item.title" placeholder="" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="Start Date">
                  <el-date-picker
                    v-model="item.startTime"
                    value-format="yyyy-MM"
                    type="month"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="End Date">
                  <el-date-picker
                    v-model="item.endTime"
                    value-format="yyyy-MM"
                    type="month"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label-width="80px" label="Description">
                  <editor v-model="item.description" :min-height="392" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <el-button
          type="primary"
          round
          style="font-size: 12px;padding: 8px 12px;margin-top: 10px;"
          @click="addPro">+Add New</el-button>
      </div>

      <div style="margin-top: 50px;">
        <span style="color: #000;font-weight: bold;">Education</span>
        <div style="margin-top: 20px;">
          <el-form v-for=" (item,index) in form.schoolList"
                   :key="index" :model="item" :ref="'formData'+index"
                   label-width="80px"
                   style="border-bottom: 2px dotted #cccccc;margin-top: 10px">
            <div style="display: inline-flex;flex-direction: row-reverse;width: 100%;">
              <el-button
                @click="removeSchool(index)"
                type="danger"
                icon="el-icon-delete"
                circle size="mini"></el-button>
            </div>
            <el-row>
              <el-col :span="8">
                <el-form-item label="School" prop="name">
                  <el-input v-model="item.name" placeholder="" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="Major" prop="major">
                  <el-input v-model="item.major" placeholder="" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="Degree" prop="degree">
                  <el-input v-model="item.degree" placeholder="" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="Start Date">
                  <el-date-picker
                    v-model="item.startTime"
                    value-format="yyyy-MM"
                    type="month"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="End Date">
                  <el-date-picker
                    v-model="item.endTime"
                    value-format="yyyy-MM"
                    type="month"
                  ></el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="24">
                <el-form-item label-width="80px" label="Description">
                  <editor v-model="item.description" :min-height="392"/>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
        <el-button type="primary" round style="font-size: 12px;padding: 8px 12px;margin-top: 10px;" @click="addSchool">+Add New</el-button>
      </div>
      <el-row>
        <p style="color: #000;font-weight: bold;margin-top: 50px;">Other</p>
        <el-col :span="24" style="margin-top: 10px;">
          <el-form-item label-width="0" label="">
            <editor v-model="form.other" :min-height="392"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div style="display: flex;width: 100%;">
      <el-button type="primary" @click="submitForm" style="margin-left: 50px;">Confirm</el-button>
      <el-button @click="cancel" style="margin-left: 10px;">Cancel</el-button>
    </div>

  </div>
</template>

<script>
import { listCandidate, getCandidate, delCandidate, addCandidate, updateCandidate } from "@/api/system/candidate";
import { getToken } from "@/utils/auth";
import { area } from '@/utils/area';
import { CodeToText } from 'element-china-area-data';



export default {
  name: "CandidateAdd",
  props: {
    // 值
    value: [String, Object, Array],
    // 数量限制
    limit: {
      type: Number,
      default: 115,
    },
    // 大小限制(MB)
    fileSize: {
      type: Number,
      default: 5,
    },
    // 文件类型, 例如['png', 'jpg', 'jpeg']
    fileType: {
      type: Array,
      default: () => ["docx", "pdf"],
    }
  },
  dicts: ['sys_hk_district', 'sys_mhk_district', 'sys_user_sex'],
  data() {
    return {
      number: 0,
      uploadList: [],
      baseUrl: process.env.VUE_APP_BASE_API,
      uploadFileUrl: process.env.VUE_APP_BASE_API + "/system/candidate/upload", // 上传文件服务器地址
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      fileList: [],
      type: 0,
      isMainlang: false,
      isHK: false,
      optionsCity: [], //选中的省市区
      options: area,
      // 遮罩层
      // 选中数组
      openFile: false,
      openFileDoc: false,
      vHtml: "",
      wordURL:'',  //文件地址，看你对应怎末获取、赋值
      id: null,
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      candidateList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      uploadUrl: "http://jobslink.megaslink.com/prod-api" + "/common/upload", // process.env.VUE_APP_BASE_API上传的图片服务器地址
      headers: {
        Authorization: "Bearer " + getToken()
      },
      formJobs: {},
      ruleJobs: {
        com: [
          { required: true, message: "company null", trigger: "blur" }
        ],
        title: [
          { required: true, message: "title null", trigger: "blur" }
        ],
      },
      // 查询参数
      queryParams: {
        id: null,
        pageNum: 1,
        pageSize: 10,
        email1: null,
        email2: null,
        name: null,
        phone1: null,
        phone2: null,
        gender: null,
        salary: null,
        education: null,
        other: null,
        district: null,
        age: null,
        birthyear: null
      },
      isCascaderShow: false,
      fileData: {name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100'},
      // 表单参数
      form: {
        id: null,
        email1: null,
        email2: null,
        name: null,
        phone1: null,
        phone2: null,
        gender: null,
        salary: null,
        education: null,
        other: null,
        district: null,
        area: null,
        cnAddr: null,
        age: null,
        birthyear: null,
        filePath: null,
        fileList: [],
        ccompanyList: [
          {
            id: null,
            cid: null,
            com: null,
            title: null,
            startTime: null,
            endTime: null,
            description: null
          }
        ],
        proList: [
          {
            id: null,
            title: null,
            startTime: null,
            endTime: null,
            description: null
          }
        ],
        schoolList: [
          {
            id: null,
            name: null,
            major: null,
            degree: null,
            description: null,
            startTime: null,
            endTime: null
          }
        ]
      },
      // 表单校验
      rules: {
        email1: [
          { required: true, message: "email is null", trigger: "blur" }
        ],
        name: [
          { required: true, message: "name is null", trigger: "blur" }
        ],
        phone1: [
          { required: true, message: "phone is null", trigger: "blur" }
        ],
      },
      pdfUrl: null,
      pageTotal: null
    };
  },
  // 给Vue的实例注入数据，进行数据监听
  created() {
    console.log("created");
    this.id = this.$route.query.id;
    this.type = this.$route.query.type;
    if (this.id == null || this.id == '' || this.id  == undefined) {
      this.$nextTick(() => {
        this.scrollToTop();
      })
    } else {
      this.queryParams.id = this.id;
      this.getList();
    }
  },
  methods: {
    // 上传前校检格式和大小
    handleBeforeUploadCV(file) {
      // 校检文件类型
      if (this.fileType) {
        const fileName = file.name.split('.');
        const fileExt = fileName[fileName.length - 1];
        const isTypeOk = this.fileType.indexOf(fileExt) >= 0;
        if (!isTypeOk) {
          this.$modal.msgError(`File format error, please upload ${this.fileType.join("/")} format!`);
          return false;
        }
      }
      // 校检文件大小
      if (this.fileSize) {
        const isLt = file.size / 1024 / 1024 < this.fileSize;
        if (!isLt) {
          this.$modal.msgError(`file size more than ${this.fileSize} MB!`);
          return false;
        }
      }
      this.$modal.loading("loading...");
      this.number++;
      return true;
    },
    // 文件个数超出
    handleExceedCV() {
      // this.$modal.msgError(`上传文件数量不能超过 ${this.limit} 个!`);
    },
    // 上传失败
    handleUploadErrorCV(err) {
      this.$modal.msgError("error, again");
      this.$modal.closeLoading()
    },
    // 上传成功回调
    handleUploadSuccessCV(res, file) {
      if (res.code === 200) {
        this.$modal.closeLoading();
        // 上传成功
        this.form = res.data;
        if (this.form.cnAddr == null || this.form.cnAddr == '' || this.form.cnAddr == undefined) {

        } else {
          let optionsCityT = this.form.cnAddr.split(",");
          for (let i = 0; i < optionsCityT.length; i++) {
            this.optionsCity.push(parseInt(optionsCityT[i]));
          }
          console.log(this.optionsCity);
          this.$nextTick(() => {
            this.isCascaderShow = true;
          })
          console.log(this.isCascaderShow);
        }
        if (this.form.area == 'HK'){
          this.isHK = true;
          this.isMainlang = false;
        } else {
          this.isHK = false;
          this.isMainlang = true;
        }
        if (this.form.ccompanyList == null || this.form.ccompanyList.length == 0) {
          this.form.ccompanyList.push({
            id: null,
            cid: null,
            com: null,
            title: null,
            startTime: null,
            endTime: null,
            description: null
          })
        }
        if (this.form.schoolList == null || this.form.schoolList.length == 0) {
          this.form.schoolList.push({
            id: null,
            name: null,
            major: null,
            degree: null,
            description: null,
            startTime: null,
            endTime: null
          })
        }
        this.form.fileList = [];
        if (this.form.filePath != null && this.form.filePath != '') {
          this.form.fileListPath = this.form.filePath.split(",");
          for (let i = 0; i < this.form.fileListPath.length; i++) {
            this.form.fileList.push({
              name: this.form.fileListPath[i].substring(this.form.filePath.lastIndexOf('/') + 1),
              url: this.form.fileListPath[i]
            });
          }
        }
        this.$nextTick(() => {
          this.scrollToTop();
        })
        this.uploadedSuccessfullyCV();
      } else {
        // 上传失败
        this.$modal.closeLoading();
        this.$modal.msgError(res.msg);
        this.$refs.fileUpload.handleRemove(file);
        this.uploadedSuccessfullyCV();
      }
    },
    // 删除文件
    handleDeleteCV(index) {
      this.fileList.splice(index, 1);
      this.$emit("input", this.listToString(this.fileList));
    },
    // 上传结束处理
    uploadedSuccessfullyCV() {
      // if (this.number > 0 && this.uploadList.length === this.number) {
      //   this.fileList = this.fileList.concat(this.uploadList);
      //   this.uploadList = [];
      //   this.number = 0;
      //   this.$emit("input", this.listToString(this.fileList));
      //   this.$modal.closeLoading();
      // }
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        email1: null,
        email2: null,
        name: null,
        phone1: null,
        phone2: null,
        gender: null,
        salary: null,
        education: null,
        other: null,
        district: null,
        area: null,
        cnAddr: null,
        age: null,
        birthyear: null,
        filePath: null,
        fileList: [],
        ccompanyList: [
          {
            id: null,
            cid: null,
            com: null,
            title: null,
            startTime: null,
            endTime: null,
            description: null
          }
        ],
        schoolList: [
          {
            id: null,
            name: null,
            major: null,
            degree: null,
            description: null,
            startTime: null,
            endTime: null
          }
        ]
      };
      this.resetForm("form");
    },
    searchBuilds() {
      // let province = []
      // let city = []
      // let area = []
      // let province1 = []
      // let city1 = []
      // let area1 = []
      // if (this.optionsCity) {
      //   this.optionsCity.forEach((v) => {
      //     province.push(CodeToText[v[0]]) //中文的
      //     city.push(CodeToText[v[1]])
      //     area.push(CodeToText[v[2]])
      //
      //     province1.push(v[0]) //编码的
      //     city1.push(v[1])
      //     area1.push(v[2])
      //   })
      //   province = Array.from(new Set(province)).toString()
      //   city = Array.from(new Set(city)).toString()
      //   area = Array.from(new Set(area)).toString()
      //
      //   province1 = Array.from(new Set(province1)).toString()
      //   city1 = Array.from(new Set(city1)).toString()
      //   area1 = Array.from(new Set(area1)).toString()
      // }
      // console.log(province, 'province')
      // console.log(city, 'city')
      // console.log(area, 'area')
      // console.log(province1, 'province1')
      // console.log(city1, 'city1')
      // console.log(area1, 'area1')
    },
    // 下拉框可输可选
    selectBlur(e) {
      // if (e.target.value !== '') {
      //   // this.$set(this.form, 'district', e.target.value);
      //   this.form.district = e.target.value + '(其他)';
      //   this.$forceUpdate();   // 强制更新
      // }
    },
    selectClear() {
      this.form.district = '';
      this.$forceUpdate();
    },
    selectAreaChange(val) {
      this.form.area = val;
      if (this.form.area == 'HK') {
        this.isHK = true;
        this.isMainlang = false;
      } else {
        this.isHK = false;
        this.isMainlang = true;
        this.isCascaderShow = true;
      }
      this.$forceUpdate();
    },
    selectChange(val) {
      this.form.district = val;
      this.$forceUpdate();
    },
    scrollToTop() {
      window.scrollTo({
        top: 0,
        behavior: "smooth"
      });
    },
    removeSchool(index) {
      if (this.form.schoolList.length <= 1) {
        this.$modal.msgError("Keep at least one");
        return;
      }
      this.form.schoolList.splice(index, 1);
    },
    removeJobs(index) {
      if (this.form.ccompanyList.length <= 1) {
        this.$modal.msgError("Keep at least one");
        return;
      }
      this.form.ccompanyList.splice(index, 1);
    },
    removePro(index) {
      if (this.form.proList.length <= 1) {
        this.$modal.msgError("Keep at least one");
        return;
      }
      this.form.proList.splice(index, 1);
    },
    addSchool() {
      this.form.schoolList.push({
        id: null,
        name: null,
        major: null,
        degree: null,
        description: null,
        startTime: null,
        endTime: null
      });
    },
    addJobs() {
      this.form.ccompanyList.push({
        id: null,
        cid: null,
        com: null,
        title: null,
        startTime: null,
        endTime: null,
        description: null
      });
    },
    addPro() {
      this.form.proList.push({
        id: null,
        title: null,
        startTime: null,
        endTime: null,
        description: null
      });
    },
    handleRemove(file, fileList) {
      console.log(file);
      console.log(fileList);
      if (file.status == "success") {
        this.form.fileList = this.form.fileList.filter(item => {
          return !(item.name == file.name && item.url == file.url);
        } );
      }
      console.log(this.form.fileList);
    },
    handlePreview(file) {
      console.log(file);
      // 截取上传文件的后缀名
      let fileType = file.name.substring(file.name.lastIndexOf(".") + 1);
      console.log(fileType);
      // 判断文件名的类型，允许多种就判断多个
      if (fileType.toLocaleLowerCase() == 'pdf' || fileType.toLocaleLowerCase() == 'doc' || fileType.toLocaleLowerCase() == 'docx') {
        let Base64 = require('js-base64').Base64
        window.open('http://www.megaslink.com:8012/onlinePreview?url='+encodeURIComponent(Base64.encode(this.form.filePath)));
      } else {
        this.$message.warning("文件类型必须为pdf,doc,docx格式")
        // 返回false 就不会执行上传操作了
        return false
      }
    },
    handleExceed(files, fileList) {
      // this.$message.warning(`当前限制只能上传 1 个文件或者删除重新上传`);
    },
    handleFileSuccess(response, file, fileList) {
      console.log(response);
      console.log(file);
      console.log(fileList);
      if (response.code == 200) {
        console.log("================" + response.url);
        this.form.filePath = response.url;
        this.form.fileList.push( {
            name: file.name,
            url: response.url
          }
        )
        console.log(this.form.fileList);
      } else {
        this.$message.warning(`上传失败`);
        // this.form.fileList.splice(this.form.fileList.length - 1, 1);
      }
      // fileList[0].response.url;

    },
    beforeRemove(file, fileList) {
      return this.$confirm(`Remove ${ file.name }？`);
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      // this.optionsCity = [110000,110100,110101];
      this.$modal.loading("loading...");
      // this.$modal.closeLoading();
      listCandidate(this.queryParams).then(response => {
        this.candidateList = response.rows;
        if (this.candidateList != null) {
          this.form = this.candidateList[0];
          if (this.form.cnAddr == null || this.form.cnAddr == '' || this.form.cnAddr == undefined) {

          } else {
            let optionsCityT = this.form.cnAddr.split(",");
            for (let i = 0; i < optionsCityT.length; i++) {
              this.optionsCity.push(parseInt(optionsCityT[i]));
            }
            console.log(this.optionsCity);
            this.$nextTick(() => {
              this.isCascaderShow = true;
            })
            console.log(this.isCascaderShow);
          }
          if (this.form.area == 'HK'){
            this.isHK = true;
            this.isMainlang = false;
          } else {
            this.isHK = false;
            this.isMainlang = true;
          }
          if (this.form.ccompanyList == null || this.form.ccompanyList.length == 0) {
            this.form.ccompanyList.push({
              id: null,
              cid: null,
              com: null,
              title: null,
              startTime: null,
              endTime: null,
              description: null
            })
          }
          if (this.form.proList == null ||
            this.form.proList.length == 0) {
            this.form.proList.push({
              id: null,
              title: null,
              startTime: null,
              endTime: null,
              description: null
            })
          }
          if (this.form.schoolList == null || this.form.schoolList.length == 0) {
            this.form.schoolList.push({
              id: null,
              name: null,
              major: null,
              degree: null,
              description: null,
              startTime: null,
              endTime: null
            })
          }
          this.form.fileList = [];
          if (this.form.filePath != null && this.form.filePath != '') {
            this.form.fileListPath = this.form.filePath.split(",");
            for (let i = 0; i < this.form.fileListPath.length; i++) {
              this.form.fileList.push({
                name: this.form.fileListPath[i].substring(this.form.filePath.lastIndexOf('/') + 1),
                url: this.form.fileListPath[i]
              });
            }
          }
        }
        this.$nextTick(() => {
          this.scrollToTop();
        })
        this.$modal.closeLoading();
      });
    },
    // 取消按钮
    cancel() {
      if(this.type == 1) {
        const obj = { path: "/cand/entry", name: "CandidateEntry" };
        this.$tab.closePage(obj);
        setTimeout(()=> {
          const obj = { path: "/cand/entry" };
          this.$tab.closeOpenPage(obj);
        }, 300);
      } else {
        const obj = { path: "/cand/candidate", name: "Candidate" };
        this.$tab.closePage(obj);
        setTimeout(()=> {
          const obj = { path: "/cand/candidate" };
          this.$tab.closeOpenPage(obj);
        }, 300);
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        email1: null,
        email2: null,
        name: null,
        phone1: null,
        phone2: null,
        gender: null,
        salary: null,
        education: null,
        other: null,
        district: null,
        age: null,
        birthyear: null
      };
      this.resetForm("form");
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.area == null || this.form.area == undefined ||
            this.form.area == '') {
            this.$modal.msgWarning("area is null");
            return;
          }
          //手机验证
          if (this.form.area == "HK") {
            if (this.form.phone1.length != 8) {
              this.$modal.msgWarning("Limit the number to 8");
              return;
            }
          } else {
            if (this.form.phone1.length != 11) {
              this.$modal.msgWarning("Limit the number to 11");
              return;
            }
          }
          if (this.optionsCity.length > 0) {
            this.form.cnAddr = this.optionsCity.join(',');
          }
          this.form.filePath = '';
          if (this.form.fileList != null && this.form.fileList.length > 0) {
            for (let i = 0; i < this.form.fileList.length; i++) {
              if (i == (this.form.fileList.length - 1)) {
                this.form.filePath = this.form.filePath + this.form.fileList[i].url;
              } else {
                this.form.filePath = this.form.filePath + this.form.fileList[i].url + ",";
              }
            }
          }
          if (this.form.id != null) {
            updateCandidate(this.form).then(response => {
              this.$modal.msgSuccess("success");
              if(this.type == 1) {
                const obj = { path: "/cand/entry", name: "CandidateEntry" };
                this.$tab.closePage(obj);
                setTimeout(()=> {
                  const obj = { path: "/cand/entry" };
                  this.$tab.closeOpenPage(obj);
                }, 300);
              } else {
                const obj = { path: "/cand/candidate", name: "Candidate" };
                this.$tab.closePage(obj);
                setTimeout(()=> {
                  const obj = { path: "/cand/candidate" };
                  this.$tab.closeOpenPage(obj);
                }, 300);
              }
            });
          } else {
            addCandidate(this.form).then(response => {
              this.$modal.msgSuccess("success");
              if(this.type == 1) {
                const obj = { path: "/cand/entry", name: "CandidateEntry" };
                this.$tab.closePage(obj);
                setTimeout(()=> {
                  const obj = { path: "/cand/entry" };
                  this.$tab.closeOpenPage(obj);
                }, 300);
              } else {
                const obj = { path: "/cand/candidate", name: "Candidate" };
                this.$tab.closePage(obj);
                setTimeout(()=> {
                  const obj = { path: "/cand/candidate" };
                  this.$tab.closeOpenPage(obj);
                }, 300);
              }
            });
          }
        }
      });
    }
  }
};
</script>
<style rel="stylesheet/scss" lang="scss">
  .card3 {
    background-image: linear-gradient(to right, #000 35%, rgba(255,255,255,0) 0%); /* 35%设置虚线点x轴上的长度 */
    background-position: bottom; /* top配置上边框位置的虚线 */
    background-size: 10px 1px; /* 第一个参数设置虚线点的间距；第二个参数设置虚线点y轴上的长度 */
    background-repeat: repeat-x;
  }
  .ql-editor.ql-blank::before{
    content: "";
  }
</style>
